﻿var http_request;
function send_request(url,poststr,cfunc) {
    http_request = false;
    if(window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    }else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) return false;
    http_request.onreadystatechange = cfunc;
    http_request.open("POST", url, true);
    http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    http_request.send(poststr);
}

//////////////////////购物车页面/////////////////////////
function changeShoppingCart(obj){
    var returnValue=obj.split("〇");
    if(returnValue[0]=="1001"){
       art.dialog.tips(returnValue[1],1.5);
    }else if(returnValue[0]=="1002"){
       art.dialog.tips("很抱歉，换购失败，商品库存不足！",1.5);
    }else if(returnValue[0]=="2001"){
       art.dialog.tips("很抱歉，此操作导致商品总额不足换购商品，商品数量修改失败！",1.5);
    }else if(returnValue[0]=="2002"){
       art.dialog.tips("很抱歉，商品数量修改失败，商品库存不足！",1.5);
    }else if(returnValue[0]=="3001"){
       art.dialog.tips("很抱歉，此操作导致商品总额不足换购商品，商品删除失败！",1.5);
    }else{
        $("#tbShoppingCart").html(returnValue[1]);
        $("#pTotal").html(returnValue[2]);
        $("#increaseArea").html(returnValue[3]);
        $(".myshoppingcart").html(returnValue[4]);
        $(".addprice").each(function(){
            var classname=$(this).attr("rel")
            $(this).addClass(classname);
            $("."+classname).infiniteCarousel();
        });
        $("input[name=increaseJia]").click(function(){
            var id=$(this).attr("id").replace("jia_","#increaseAmount_");
            $(id).val(parseInt($(id).val())+1);   
        });
        $("input[name=increaseJian]").click(function(){
            var id=$(this).attr("id").replace("jian_","#increaseAmount_");
            if(parseInt($(id).val())>0)
                $(id).val(parseInt($(id).val())-1);
        });
        $("input[name=increaseSubmit]").click(function(){
            var id=$(this).attr("id").replace("submit_","#increaseAmount_");
            if(parseInt($(id).val())==0){
                art.dialog.tips("请输入购买数量！",1.5);
                return false;
            }else{
                var poststr = "pid="+id.split('_')[1]+"&gid="+id.split('_')[2]+"&amount="+parseInt($(id).val());
                send_request("/ashx/cn/1store/shopping_cart.ashx",poststr,function(){
                    if (http_request.readyState==4 && http_request.status==200){
                        changeShoppingCart(http_request.responseText);
                    }    
                });
            }
        });
    }
    return false;
}
function amountJia(obj){
    poststr = "cid="+obj+"&amount="+(parseInt($("#amount"+obj).val())+1);
    send_request("/ashx/cn/1store/shopping_cart.ashx",poststr,function(){
        if (http_request.readyState==4 && http_request.status==200){
            changeShoppingCart(http_request.responseText);
        }    
    });
}
function amountJian(obj){
    if(parseInt($("#amount"+obj).val())>1){
        poststr = "cid="+obj+"&amount="+(parseInt($("#amount"+obj).val())-1);
        send_request("/ashx/cn/1store/shopping_cart.ashx",poststr,function(){
            if (http_request.readyState==4 && http_request.status==200){
                changeShoppingCart(http_request.responseText);
            }    
        });
    }
}
function changeAmount(obj){
    if(parseInt($("#amount"+obj).val())==0){
        art.dialog.tips("购买数量不能为0！",1.5);
        return false;
    }    
    poststr = "cid="+obj+"&amount="+$("#amount"+obj).val();
    send_request("/ashx/cn/1store/shopping_cart.ashx",poststr,function(){
        if (http_request.readyState==4 && http_request.status==200){
            changeShoppingCart(http_request.responseText);
        }    
    });
}
$(function(){
    $("#imgSettlement").click(function(){
        $.ajax({
           type:"POST",
            url:"/ashx/cn/1store/detection_session.ashx",
            success:function(msg){
                if(msg=="1001")
                    TB_show(null, "/cn/login.html?TB_iframe=true&height=370&width=640", false);
                else if(msg=="1002")
                    art.dialog.tips("购物车目前没有加入任何商品！",1.5);
                else if(msg=="1000")    
                    window.location="/cn/order/submit.html";
            }
        });
        return false;
    });
    $("input[name=increaseJia]").click(function(){
        var id=$(this).attr("id").replace("jia_","#increaseAmount_");
        $(id).val(parseInt($(id).val())+1);   
    });
    $("input[name=increaseJian]").click(function(){
        var id=$(this).attr("id").replace("jian_","#increaseAmount_");
        if(parseInt($(id).val())>0)
            $(id).val(parseInt($(id).val())-1);
    });
    $("input[name=increaseSubmit]").click(function(){
        var id=$(this).attr("id").replace("submit_","#increaseAmount_");
        if(parseInt($(id).val())==0){
            art.dialog.tips("请输入购买数量！",1.5);
            return false;
        }else{
            var poststr = "pid="+id.split('_')[1]+"&gid="+id.split('_')[2]+"&amount="+parseInt($(id).val());
            send_request("/ashx/cn/1store/shopping_cart.ashx",poststr,function(){
                if (http_request.readyState==4 && http_request.status==200){
                    changeShoppingCart(http_request.responseText);
                }    
            });
        }
    });
});
function deleteShoppingCart(obj){
    send_request("/ashx/cn/1store/shopping_cart.ashx",'sid='+obj,function(){
        if (http_request.readyState==4 && http_request.status==200){
            changeShoppingCart(http_request.responseText);
        }    
    });
}


///////////////////商品详细页/////////////////////////
$(function(){
    $("#btnGoodsComment").click(function(){
        if($("#txtaContent").val()==""){
            $("#txtaContent").select();
            art.dialog.tips("请输入评论内容！",1.5);
            return false;
        }else{
            if($("#txtaContent").val().length>500){
                $("#txtaContent").select();
                art.dialog.tips("评论内容不能超过500个字符！",1.5);
                return false;
            }
        }
        if($("#txtCommentCode").val()==""){
            $("#txtCommentCode").select();
            art.dialog.tips("请输入验证码！",1.5);
            return false;
        }
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/goods_comment.ashx",
            data:"id="+$("#hdGoods").val()+"&contact="+escape($("#txtContact").val())+"&content="+escape($("#txtaContent").val())+"&code="+$("#txtCommentCode").val(),
            success:function(msg){
                if(msg=="0"){
                    TB_show(null, "/cn/login.html?TB_iframe=true&height=370&width=640", false);
                }else if(msg=="1"){
                    $("#txtCommentCode").select();
                    art.dialog.tips("验证码错误，请重新输入！",1.5);
                    $("#imgCheckCommentCode").attr("src","/code/"+ parseInt(10000*Math.random())+"_conmment.html");
                }else if(msg=="2"){
                    art.dialog.tips("很抱歉，评论失败！",1.5);
                }
                else{
                    art.dialog.tips("恭喜您，评论成功！",1.5);
                    $(".comment_title").html(msg.split('〇')[0]);
                    $("#goods_comment").html(msg.split('〇')[1]);
                    $("#imgCheckCommentCode").attr("src","/code/"+ parseInt(10000*Math.random())+"_conmment.html");
                    $("#formComment")[0].reset();
                    gotopage();
                }
            }
        });
        return false;
    });
    $(".gotopage").click(function(){
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/goods_comment.ashx",
            data:"id="+$("#hdGoods").val()+"&pageIndex="+$(this).attr("rel"),
            success:function(msg){
                if(msg=="2"){
                    art.dialog.tips("数据获取失败！",1.5);
                }
                else{
                    $("#goods_comment").html(msg);
                    gotopage();
                }
            }
        });
        return false;
    });
    function gotopage()
    {
        $(".gotopage").click(function(){
            $.ajax({
                type:"POST",
                url:"/ashx/cn/1store/goods_comment.ashx",
                data:"id="+$("#hdGoods").val()+"&pageIndex="+$(this).attr("rel"),
                success:function(msg){
                    if(msg=="2"){
                        art.dialog.tips("数据获取失败！",1.5);
                    }
                    else{
                        $("#goods_comment").html(msg);
                        gotopage();
                    }
                }
            });
            return false;
        });
    }
    $("#btnScoreSubmit").click(function(){
        if($("input[name='commodityScore']:checked").val()==null){
            art.dialog.tips("请选择星级！",1.5);
            return false;
        }else{
            $.ajax({
                type:"POST",
                url:"/ashx/cn/1store/goods_score.ashx",
                data:"id="+$("#hdGoods").val()+"&score="+$("input[name='commodityScore']:checked").val(),
                success: function (msg) {
                    if(msg=="0"){
                        TB_show(null, "/cn/login.html?TB_iframe=true&height=370&width=640", false);
                    }
                    else if(msg=="1"){
                        art.dialog.tips("很抱歉，评分失败！",1.5);
                    }else{
                        art.dialog.tips("恭喜您，评分成功！",1.5);
                        $('#formScore')[0].reset();//表单重置
                        $("#pScore").html(msg.split("+")[0]);
                        $("#divScore").html(msg.split("+")[1]);
                    }
                }
            });
            return false;
        }
    });
    $("#btnCountJian").click(function(){
        if(parseInt($("#txtCount").val())>0)
            $("#txtCount").val(parseInt($("#txtCount").val())-1);
    });
    $("#btnCountJia").click(function(){
        if(parseInt($("#spInventory").text())>parseInt($("#txtCount").val()))
            $("#txtCount").val(parseInt($("#txtCount").val())+1);
    });
    ///商品收藏
    $("#aFavorites").click(function(){
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/goods_favorites.ashx",
            data:"id="+$("#hdGoods").val(),
            success:function(msg){
                if(msg=="0") TB_show(null, "/cn/login.html?TB_iframe=true&height=370&width=640", false);
                else if(msg=="1") art.dialog.tips("此商品已收藏，请不要重复添加！",1.5);
                else if(msg=="2") art.dialog.tips("恭喜您，收藏成功！",1.5);
                else if(msg=="3") art.dialog.tips("很抱歉，收藏失败！",1.5);
            }
        });
        return false;
    });
    $("#aAddShoppingCart").click(function(){
        if($("#txtCount").val()=="0"){
            art.dialog.tips("请输入购买数量！",1.5);
            return false;
        }
        else {
            $.ajax({
                type:"POST",
                url:"/ashx/cn/1store/add_shopping_cart.ashx",
                data:"goodsEntitys="+$("#hdGoodsEntitys").val()+"&count="+$("#txtCount").val(),
                success:function(msg){
                    if(msg=="1002") art.dialog.tips("添加购物车失败，商品库存不足！",1.5);
                    else{ 
                        $(".shopping_car").html(msg.split('〇')[1]);
                        $("#shopcart").html(msg.split('〇')[2]);
                        customButton('添加至购物车成功！','立即结算','/cn/shopping/cart.html','继续购物');
                    }   
                }
            });
        }
        return false;
    });
});
function chooseSpecifications(ge,s,sv)
{
    poststr = "goodsEntitys="+ge+"&specifications="+s+"&specificationsValue="+sv+"&goods="+$("#hdGoods").val()+"&SpecificationsList="+$("#hdSpecificationsList").val()+"&SpecificationsValueList="+$("#hdSpecificationsValueList").val();
    send_request("/ashx/cn/1store/specifications.ashx",poststr,function(){
        if (http_request.readyState==4 && http_request.status==200){
            if(http_request.responseText!="")
            {
                var returnValue=http_request.responseText.split("〇");
                $("#goodsArtno").text(returnValue[0]);
                $("#pPrice").html(returnValue[1]);
                $("#spInventory").html(returnValue[2]);
                if(parseInt(returnValue[2])>0) $("#txtCount").val("1");
                else $("#txtCount").val("0"); 
                $("#hdSpecificationsValueList").val(returnValue[3]);
                $("#liChooseSpecifications").html(returnValue[4]);
                $("#liSpecifications").html(returnValue[5]);
                $("#hdGoodsEntitys").val(returnValue[6]);
            }
            return false;
        }    
    });
}
function changeFreight(fid,rn,name){
    poststr = "fid="+fid+"&rn="+escape(rn);
    send_request("/ashx/cn/1store/freight_way.ashx",poststr,function(){
        if (http_request.readyState==4 && http_request.status==200){
            if(http_request.responseText!="")
            {
                $("#pFreight").html(http_request.responseText);
                $("#region").html(name);
                $("a[s]").removeClass('sbg');
                $(".city").hide();
                $("#storeinfo").removeClass('hover');
            }
            return false;
        }    
    });
}

////////////////////////////会员登录//////////////////////////////////////
$(function () {
    $("#txtUserName").blur(function () {
        if ($("#txtUserName").val() == "") {
            $("#spUserName").html("<img src=\"/cn/images/wrong.gif\" /> 请输入用户名！");
        }
        else $("#spUserName").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#txtUserPwd").blur(function () {
        if ($("#txtUserPwd").val() == "") {
            $("#spPwd").html("<img src=\"/cn/images/wrong.gif\" /> 请输入密码！");
        } else $("#spPwd").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#txtCode").blur(function () {
        if ($("#txtCode").val() == "") {
            $("#spCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入验证码！");
        } else $("#spCode").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#formLogin").submit(function () {
        ///用户名
        if ($("#txtUserName").val() == "") {
            $("#txtUserName").select();
            $("#spUserName").html("<img src=\"/cn/images/wrong.gif\" /> 请输入用户名！");
            return false;
        }
        else $("#spUserName").html("<img src=\"/cn/images/right.gif\"/>");
        ///用户密码
        if ($("#txtUserPwd").val() == "") {
            $("#txtUserPwd").select();
            $("#spPwd").html("<img src=\"/cn/images/wrong.gif\" /> 请输入密码！");
            return false;
        } else $("#spPwd").html("<img src=\"/cn/images/right.gif\"/>");
        ///验证码
        if ($("#txtCode").val() == "") {
            $("#txtCode").select();
            $("#spCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入验证码！");
            return false;
        } else $("#spCode").html("<img src=\"/cn/images/right.gif\"/>");
        var action = $.getUrlVar('action');
        $.ajax({
            type: "POST",
            url: "/loginHandler.ashx",
            data: "userName=" + escape($("#txtUserName").val()) + "&userPwd=" + escape($("#txtUserPwd").val()) + "&code=" + escape($("#txtCode").val()) + "&action=" + escape(action),
            success: function (msg) {
                if (msg == "0") {
                    $("#txtCode").select();
                    $("#spCode").html("<img src=\"/cn/images/wrong.gif\" /> 验证码错误！");
                    $("#spUserName").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#imgCheckCode").attr("src", "/admin/checkCode.aspx?id=" + parseInt(10000 * Math.random()) );
                }
                else if (msg == "1") {
                    $("#txtUserName").select();
                    $("#spUserName").html("<img src=\"/cn/images/wrong.gif\" /> 用户名不存在！");
                    $("#spCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "2") {
                    $("#txtUserPwd").select();
                    $("#spPwd").html("<img src=\"/cn/images/wrong.gif\" /> 用户名或密码错误！");
                    $("#spUserName").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "3") {
                    $("#txtUserName").select();
                    $("#spUserName").html("<img src=\"/cn/images/wrong.gif\" /> 该用户被停用！");
                    $("#spPwd").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "4") {
                    art.dialog.tips("恭喜您，登录成功！", 1.5);
                    setTimeout("parent.location.reload()", 2000);

                }
                else if (msg == "5") {
                    art.dialog.tips("恭喜您，登录成功！", 1.5);
                    setTimeout("window.location.href='exchange.aspx'", 2000);
                }
                else if (msg == "6") {
                    art.dialog.tips("恭喜您，登录成功！", 1.5);
                    setTimeout("parent.location.href='account.aspx'", 2000);
                }

            }
        });
        return false;
    });
    $("#btnMemberRegister").click(function () {
        window.location.href = "/cn/register.aspx?TB_iframe=true&height=370&width=640&action=" + $.getUrlVar('action');
    });

});



$.extend({getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++){
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
       return vars;
     }, getUrlVar: function(name){

 return $.getUrlVars()[name];
  }
});



////////////////////////////卡券提货//////////////////////////////////////
$(function () {
    $("#txtCardCode").blur(function () {
        if ($("#txtCardCode").val() == "") {
            $("#txtCardCode").select();
            $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入卡券号！");
        }
        else $("#spCardCode").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#txtCardPwd").blur(function () {
        if ($("#txtCardPwd").val() == "") {
            $("#spCardPwd").html("<img src=\"/cn/images/wrong.gif\" /> 请输入卡券密码！");
        } else $("#spCardPwd").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#txtValidateCode").blur(function () {
        if ($("#txtValidateCode").val() == "") {
            $("#spValidateCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入验证码！");
        } else $("#spValidateCode").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#formCardCodeLogin").submit(function () {

        if ($("#txtCardCode").val() == "") {
            $("#txtCardCode").select();
            $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入卡券号！");
            return false;
        }
        else $("#spCardCode").html("<img src=\"/cn/images/right.gif\"/>");
        if ($("#txtCardPwd").val() == "") {
            $("#txtCardPwd").select();
            $("#spCardPwd").html("<img src=\"/cn/images/wrong.gif\" /> 请输入卡券密码！");
            return false;
        } else $("#spCardPwd").html("<img src=\"/cn/images/right.gif\"/>");
        ///验证码
        if ($("#txtValidateCode").val() == "") {
            $("#txtValidateCode").select();
            $("#spValidateCode").html("<img src=\"/cn/images/wrong.gif\" /> 请输入验证码！");
            return false;
        } else $("#spValidateCode").html("<img src=\"/cn/images/right.gif\"/>");
        $.ajax({
            type: "POST",
            url: "/cardAddHandler.ashx",
            data: "cardCode=" + escape($("#txtCardCode").val()) + "&cardPwd=" + escape($("#txtCardPwd").val()) + "&code=" + escape($("#txtValidateCode").val()),
            success: function (msg) {

                if (msg == "-1") {
                    window.open('login.aspx', '_self');

                }
                else if (msg == "0") {
                    $("#txtValidateCode").select();
                    $("#spValidateCode").html("<img src=\"/cn/images/wrong.gif\" /> 验证码错误！");
                    $("#spCardCode").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#imgCheckCode").attr("src", "/admin/checkCode.aspx?id=" + parseInt(10000 * Math.random()));
                }
                else if (msg == "1") {
                    $("#txtCardCode").select();
                    $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 卡券号不存在！");
                    $("#spVlidateCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "2") {
                    $("#txtCardPwd").select();
                    $("#spCardPwd").html("<img src=\"/cn/images/wrong.gif\" /> 卡券号或密码错误！");
                    $("#spCardCode").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spVlidateCode").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#imgCheckCode").attr("src", "/admin/checkCode.aspx?id=" + parseInt(10000 * Math.random()));
                }
                else if (msg == "6") {
                    $("#txtCardCode").select();
                    $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 该卡号已被使用！");
                    $("#spCardPwd").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spVlidateCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "3") {
                    $("#txtCardCode").select();
                    $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 该卡号有异常，请与客服联系！");
                    $("#spCardPwd").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spVlidateCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "4") {
                    $("#txtCardCode").select();
                    $("#spCardCode").html("<img src=\"/cn/images/wrong.gif\" /> 只能添加同类型的卡券，如果不是同类型的卡券，请分批充值！");
                    $("#spCardPwd").html("<img src=\"/cn/images/right.gif\"/>");
                    $("#spVlidateCode").html("<img src=\"/cn/images/right.gif\"/>");
                }
                else if (msg == "104") {
                    art.dialog.tips("提示：您使用的卡，暂无法下单,如需预约配送请与客服联系：400-052-5757！", 100.0);
                }

                else if (msg == "105") {

                    art.dialog.tips("提示：你使用的通用类型的卡，必须要登录后充值到您的账户然后使用，如没有账户请先注册，谢谢！", 50.0);
                    setTimeout("window.open('login.aspx','_self')", 5000);
                }

                else if (msg == "5") {
                    art.dialog.tips("恭喜您，充值成功！您可以直接选择页面中所兑换商品！", 5.0);
                    setTimeout("parent.location.href='/cn/exchangeGoods.aspx'", 2000);
                }

            }
        });
        return false;
    });

});




//////////////////////////////订单提交//////////////////////////////////////
function isDisplayUserAddress(region){
    var item = $("input[name='userAddress']:checked").val();
    if(item!="0"){
        $("#addUserAddress").hide();
        poststr = "region="+escape(region);
        send_request("/ashx/cn/1store/order_info.ashx",poststr,function(){
            if (http_request.readyState==4 && http_request.status==200){
                $("#sDeliveryWay").html(http_request.responseText);
            }    
        });
    }
    else{
        $("#addUserAddress").show();
        if($("#selectProvinces option:selected").val()!="0"){
            poststr = "region="+escape($("#selectProvinces option:selected").text());
            send_request("/ashx/cn/1store/order_info.ashx",poststr,function(){
                if (http_request.readyState==4 && http_request.status==200){
                    $("#sDeliveryWay").html(http_request.responseText);
                }    
            });
        }
    }
}
function changeDeliveryWay(freight){
    if($("#hdFromFreight").val()=="false"){
        $("#sSumFreight").html(changePrice2money(""+parseFloat(freight).toFixed(2)+""));
        $("#sSumTotal").html("您共需要为订单支付："+changePrice2money(""+(parseFloat($("#hdGoodsSum").val())+parseFloat(freight))+""));
    }else if($("#hdFromFreight").val()=="true"){
        $("#sSumFreight").html(changePrice2money(""+parseFloat(0).toFixed(2)+""));
        $("#sSumTotal").html("您共需要为订单支付："+changePrice2money(""+(parseFloat($("#hdGoodsSum").val())+parseFloat(0))+""));
    }
}
function changePrice2money(s)
{
    if (/[^0-9\.]/.test(s)) return "invalid value";
    s = s.replace(/^(\d*)$/, "$1.");
    s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
    s = s.replace(".", ",");
    var re = /(\d)(\d{3},)/;
    while (re.test(s))
        s = s.replace(re, "$1,$2");
    s = s.replace(/,(\d\d)$/, ".$1");
    return "¥" + s.replace(/^\./, "0.")
}
$(function(){
    $("#selectProvinces").change(function(){
        $.ajax({
           type:"POST",
           url:"/ashx/cn/1store/region.ashx",
           data:"pid="+$("#selectProvinces").val(),
           success: function (msg) {
                $("#spanCity").html(msg);
                $("#spProvinces").html("*");
           } 
        });
        if($("#selectProvinces option:selected").val()!="0")
            $.ajax({
               type:"POST",
               url:"/ashx/cn/1store/order_info.ashx",
               data:"region="+$("#selectProvinces option:selected").text(),
               success: function (msg) {
                    $("#sDeliveryWay").html(msg);
               } 
            });
        return false;
    });
    $("#txtConsignee").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#txtConsignee").val()=="")
                $("#spConsignee").html("<img src=\"/cn/images/wrong.gif\" />请输入收货人姓名！");
            else $("#spConsignee").html("<img src=\"/cn/images/right.gif\"/>");
        }    
        return false;
    });
    $("#selectProvinces").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#selectProvinces").val()=="0")
                $("#spProvinces").html("<img src=\"/cn/images/wrong.gif\" />请选择省份/直辖市！");
            else $("#spProvinces").html("<img src=\"/cn/images/right.gif\"/>"); 
        }
        return false;
    });
    $("#txtAddress").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#txtAddress").val()=="")
                $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" />请输入详细地址！");
            else $("#spAddress").html("<img src=\"/cn/images/right.gif\"/>");
        }
        return false;    
    });
    $("#txtZipcode").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#txtZipcode").val()=="")
                    $("#spZipcode").html("<img src=\"/cn/images/wrong.gif\" />请输入邮政编码！");
            else{
                if($("#txtZipcode").val().match(/^[0-9]{6}$/)==null)
                    $("#spZipcode").html("<img src=\"/cn/images/wrong.gif\" />邮政编码格式不符！");
                else $("#spZipcode").html("<img src=\"/cn/images/right.gif\"/>");
            }
        }    
        return false;
    });
    $("#txtTelephone").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#txtTelephone").val()!=""){
                if($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/)==null)
                    $("#spTelephone").html("<img src=\"/cn/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                else $("#spTelephone").html("<img src=\"/cn/images/right.gif\"/>");
            }else{
                if($("#txtMobile").val()==""){
                    $("#spTelephone").html("");
                    $("#spMobile").html("<img src=\"/cn/images/wrong.gif\" />联系电话和手机号码至少填写一项！");
                    return false;
                }
                else{
                    $("#spMobile").html("");
                    $("#spTelephone").html("");
                }
            }
        }
        return false;
    });
    $("#txtMobile").blur(function(){
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#txtMobile").val()!=""){
                if(/^13\d{9}$/g.test($("#txtMobile").val())||(/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val()))|| (/^18[05-9]\d{8}$/g.test($("#txtMobile").val())))
                    $("#spMobile").html("<img src=\"/cn/images/right.gif\"/>");
                else
                    $("#spMobile").html("<img src=\"/cn/images/wrong.gif\" />手机号码格式不符！");
            }else{
                if($("#txtTelephone").val()==""){
                    $("#txtTelephone").select();
                    $("#spTelephone").html("");
                    $("#spMobile").html("<img src=\"/cn/images/wrong.gif\" />联系电话和手机号码至少填写一项！");
                    return false;
                }
                else{
                    $("#spMobile").html("");
                    $("#spTelephone").html("");
                }
            }
        }
        return false;
    });
    if(location.href.indexOf("/cn/order/submit.html")!=-1){
        if($("#txtStartDate").val()!=""&&$("#txtEndDate").val()!=""){
            var d1Arr=$("#txtStartDate").val().split('-');
            var d2Arr=$("#txtEndDate").val().split('-');
            v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]);
            v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]);
            if(v1>v2){
                $.ajax({
                   type:"POST",
                   url:"/ashx/cn/1store/delivery_time.ashx",
                   data:"week=",
                   success: function (msg){
                        $("#DeliveryTime").html(msg);
                   } 
                });
                return false; 
            }else{
                getWeek();
            }
        }
    }
    $("#txtStartDate").blur(function(){
        if($("#txtStartDate").val()==""){
            $("#txtStartDate").select();
            art.dialog.tips("请输入开始日期！",1.5);
            return false;
        }
        else if($("#txtEndDate").val()==""){
            $("#txtEndDate").select();
            art.dialog.tips("请输入结束日期！",1.5);
            return false;
        }else{
            var d1Arr=$("#txtStartDate").val().split('-');
            var d2Arr=$("#txtEndDate").val().split('-');
            v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]);
            v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]);
            if(v1>v2){
                $.ajax({
                   type:"POST",
                   url:"/ashx/cn/1store/delivery_time.ashx",
                   data:"week=",
                   success: function (msg){
                        $("#DeliveryTime").html(msg);
                   } 
                });
                return false; 
            }else{
                getWeek();
            }
        }
    });
    $("#txtEndDate").blur(function(){
        if($("#txtStartDate").val()==""){
            art.dialog.tips("请输入开始日期！",1.5);
            $("#txtStartDate").select();
            return false;
        }
        else if($("#txtEndDate").val()==""){
            art.dialog.tips("请输入结束日期！",1.5);
            $("#txtEndDate").select();
            return false;
        }
        else{
            var d1Arr=$("#txtStartDate").val().split('-');
            var d2Arr=$("#txtEndDate").val().split('-');
            v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]);
            v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]);
            if(v1>v2){
                $.ajax({
                   type:"POST",
                   url:"/ashx/cn/1store/delivery_time.ashx",
                   data:"week=",
                   success: function (msg){
                        $("#DeliveryTime").html(msg);
                   } 
                });
                
                
                return false; 
            }else{
                getWeek();
            }
        }
    });
    $("#btnOrderSubmit").click(function(){
            if($("input[name='userAddress']:checked").val()==null){
                $("input[name='userAddress']")[0].focus();
                art.dialog.tips("请选择填写收货地址！",1.5);
                return false;
            }    
            if($("input[name='userAddress']:checked").val()=="0"){
                if($("#txtConsignee").val()==""){
                $("#txtConsignee").select();
                $("#spConsignee").html("<img src=\"/cn/images/wrong.gif\" />请输入收货人姓名！");
                return false;
            }else $("#spConsignee").html("<img src=\"/cn/images/right.gif\"/>");
            if($("#selectProvinces").val()=="0"){
                $("#selectProvinces").focus();
                $("#spProvinces").html("<img src=\"/cn/images/wrong.gif\" />请选择省份/直辖市！");
                return false;
            }else $("#spProvinces").html("<img src=\"/cn/images/right.gif\"/>");
            if($("#selectCity")!=null){
                if($("#selectCity").val()=="0"){
                    $("#selectCity").focus();
                    $("#spProvinces").html("<img src=\"/cn/images/wrong.gif\" />请选择市(县/区)！");
                    return false;
                }else $("#spProvinces").html("<img src=\"/cn/images/right.gif\"/>");
            }
            if($("#txtAddress").val()==""){
                $("#txtAddress").select();
                $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" />请输入详细地址！");
                return false;
            }else $("#spAddress").html("<img src=\"/cn/images/right.gif\"/>");
            if($("#txtZipcode").val()==""){
                $("#txtZipcode").select();
                $("#spZipcode").html("<img src=\"/cn/images/wrong.gif\" />请输入邮政编码！");
                return false;
            }else{
                if($("#txtZipcode").val().match(/^[0-9]{6}$/)==null){
                    $("#txtZipcode").select();
                    $("#spZipcode").html("<img src=\"/cn/images/wrong.gif\" />邮政编码格式不符！");
                    return false;
                }else $("#spZipcode").html("<img src=\"/cn/images/right.gif\"/>");
            }
            if($("#txtTelephone").val()==""&&$("#txtMobile").val()==""){
                $("#txtTelephone").select();
                $("#spTelephone").html("");
                $("#spMobile").html("<img src=\"/cn/images/wrong.gif\" />联系电话和手机号码至少填写一项！");
                return false;
            }
            else $("#spMobile").html("");
            if($("#txtTelephone").val()!=""){
                if($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/)==null){
                    $("#txtTelephone").select();
                    $("#spTelephone").html("<img src=\"/cn/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                    return false;
                }else $("#spTelephone").html("<img src=\"/cn/images/right.gif\"/>");
            }else $("#spTelephone").html("");
            if($("#txtMobile").val()!=""){
                if(/^13\d{9}$/g.test($("#txtMobile").val())||(/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val()))|| (/^18[05-9]\d{8}$/g.test($("#txtMobile").val()))){
                    $("#spMobile").html("<img src=\"/cn/images/right.gif\"/>");
                }else {
                    $("#txtMobile").select();
                    $("#spMobile").html("<img src=\"/cn/images/wrong.gif\" />手机号码格式不符！");
                    return false;
                }
            }else $("#spMobile").html("");
        }
        if($("input[name='deliveryWay']:checked").val()==null){
            $("input[name='deliveryWay']")[0].focus();
            art.dialog.tips("请选择配送方式！",1.5);
            return false;
        }
        var deliveryDate="";
        if($("#txtStartDate").val()==""){
            art.dialog.tips("请输入开始日期！",1.5);
            $("#txtStartDate").select();
            return false;
        }
        if($("#txtEndDate").val()==""){
            art.dialog.tips("请输入结束日期！",1.5);
            $("#txtEndDate").select();
            return false;
        }
        if($("#txtStartDate").val()!=""&&$("#txtEndDate").val()!=""){
            var d1Arr=$("#txtStartDate").val().split('-');
            var d2Arr=$("#txtEndDate").val().split('-');
            v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]);
            v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]);
            var dateS = new Date(Date.parse(($("#txtStartDate").val()+" 23:59:59").replace(/-/g, '/')));
            var dateE = new Date(Date.parse(($("#txtEndDate").val()+" 23:59:59").replace(/-/g, '/'))); 
            var dateNow=new Date();
            if(dateS<dateNow && dateE<dateNow){
                art.dialog.tips("送货日期已过期，请重新选择！",1.5);
                $("#txtStartDate").select();
                return false;
            }
            if(v1>v2){
                $("#txtEndDate").select();
                art.dialog.tips("结束日期不能小于开始日期！",1.5);
                $.ajax({
                   type:"POST",
                   url:"/ashx/cn/1store/delivery_time.ashx",
                   data:"week=",
                   success: function (msg){
                        $("#DeliveryTime").html(msg);
                   } 
                });
                return false; 
            }else{
                deliveryDate=$("#txtStartDate").val()+"至"+$("#txtEndDate").val();
            }
        }
        var deliveryTime="";
        var isDelivery="";
        if($("input[name='cbDeliveryTime']:checked").val()!=null){
            $("input[name='cbDeliveryTime']").each(function(){
                if($(this).attr("checked")){
                    if(deliveryTime!="")
                        deliveryTime+=","+$(this).val();
                    else
                        deliveryTime+=$(this).val();
                    var cbIsDelivery="cbIsDelivery"+$(this).val();
                    if($("#"+cbIsDelivery).attr("checked")){
                        if(isDelivery!="")
                            isDelivery+=",1";
                        else
                            isDelivery+="1";
                    }        
                    else{
                        if(isDelivery!="")
                            isDelivery+=",0";
                        else
                            isDelivery+="0";
                    }
                }
            });
        }
        if($("input[name='pay_bank']:checked").val()==null){
            $("input[name='pay_bank']")[0].focus();
            art.dialog.tips("请选择支付方式！",1.5);
            return false;
        }
        if($("#txtaPostscript").val().length>200){
            $("#txtaPostscript").select();
            $("#spPostscript").html("<img src=\"/cn/images/wrong.gif\" />附言不能超过200个字符！");
            return false;
        }
        else $("#spPostscript").html("<img src=\"/cn/images/right.gif\"/>");
        var da="";
        if($("input[name='userAddress']:checked").val()=="0"){
            if($("#selectCity option:selected").text()!="")
                da="&userAddress=0&consignee="+escape($("#txtConsignee").val())+"&provinces="+escape($("#selectProvinces option:selected").text())+"&city="+escape($("#selectCity option:selected").text())+"&address="+escape($("#txtAddress").val())+"&zipCode="+$("#txtZipcode").val()+"&telephone="+$("#txtTelephone").val()+"&mobile="+$("#txtMobile").val()+"&isSave="+$("input[name='isSave']:checked").val();
            else
                da="&userAddress=0&consignee="+escape($("#txtConsignee").val())+"&provinces="+escape($("#selectProvinces option:selected").text())+"&city=&address="+escape($("#txtAddress").val())+"&zipCode="+$("#txtZipcode").val()+"&telephone="+$("#txtTelephone").val()+"&mobile="+$("#txtMobile").val()+"&isSave="+$("input[name='isSave']:checked").val();
        }
        else{
            da="&userAddress="+$("input[name='userAddress']:checked").val();
        }
        if(parseInt($("#hdGoodsSum").val())==0){
            art.dialog.tips("购物车没有加入任何商品！",1.5);
            var lurl="window.location.href='/index.html'";
            setTimeout(lurl,2000);
            return false;
        }
        art.dialog.tips("订单提交中，请耐心等候...",30);
        $.ajax({
           type:"POST",
           url:"/ashx/cn/1store/order_info.ashx",
           data:"deliveryWay="+$("input[name='deliveryWay']:checked").val()+"&pay_bank="+$("input[name='pay_bank']:checked").val()+da+"&postscript="+escape($("#txtaPostscript").val())+"&goodsSum="+$("#hdGoodsSum").val()+"&deliveryDate="+deliveryDate+"&deliveryTime="+deliveryTime+"&isDelivery="+isDelivery,
           success: function (msg) {
                if(msg!="0"){
                    $.ajax({  
                        type:"POST",
                        url: "/ashx/cn/1store/async_send_message.ashx",  
                        data:"orderNo="+msg+"&sendType=1",
                        global: false,    
                        async:true,//jQuery API里面所有Demo都使用false,但是这里必须使用Default的true!  
                        success: function(){ 
                            location.href="/cn/order/result/"+msg+".html";
                        }  
                    });
                }
           } 
        });
        return false;
    });
});

function getWeek(){
    var myDate=StringToDate($("#txtStartDate").val());//转换StringToDate
    var num=daysBetween($("#txtStartDate").val(),$("#txtEndDate").val())+1;//计算有几天（时间段的长度）
    var myArray = new Array();
    if(num<7){
        for(var i=0;i<num;i++){
            var weekNum=(myDate.DateAdd('d',i)).Format('w');//遍历时间段判断每一天是周几
            if(weekNum=='日') myArray[myArray.length]="0";
            if(weekNum=='一') myArray[myArray.length]="1";
            if(weekNum=='二') myArray[myArray.length]="2";
            if(weekNum=='三') myArray[myArray.length]="3";
            if(weekNum=='四') myArray[myArray.length]="4";
            if(weekNum=='五') myArray[myArray.length]="5";
            if(weekNum=='六') myArray[myArray.length]="6";
        }
    }else{
        myArray[0]="0";
        myArray[1]="1";
        myArray[2]="2";
        myArray[3]="3";
        myArray[4]="4";
        myArray[5]="5";
        myArray[6]="6";
    }
    $.ajax({
       type:"POST",
       url:"/ashx/cn/1store/delivery_time.ashx",
       data:"week="+myArray,
       success: function (msg){
            $("#DeliveryTime").html(msg);
       } 
    });
    return false;  
}

// 求两个时间的天数差 日期格式为 YYYY-MM-dd
function daysBetween(DateOne,DateTwo) 
{   
   var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-')); 
   var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1); 
   var OneYear = DateOne.substring(0,DateOne.indexOf ('-')); 
   var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-')); 
   var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1); 
   var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-')); 
   var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);   
   return Math.abs(cha); 
} 
   
////日期计算(加几天)。本方法相当于重载（第一个参数是‘n、s、h、d、q……’，第二个参数是要加的长度）
Date.prototype.DateAdd = function(strInterval, Number) {   
    var dtTmp = this; 
    switch (strInterval) {   
        case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number)); 
        case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number)); 
        case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number)); 
        case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number)); 
        case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); 
        case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
        case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
        case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
    } 
} 
   
////////////////////////格式化日期  
Date.prototype.Format = function(formatStr)   
{   
    var str = formatStr;   
    var Week = ['日','一','二','三','四','五','六'];
    str=str.replace(/yyyy|YYYY/,this.getFullYear());   
    str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
    str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());   
    str=str.replace(/M/g,this.getMonth());
    str=str.replace(/w|W/g,Week[this.getDay()]);
    str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());   
    str=str.replace(/d|D/g,this.getDate());
    str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());   
    str=str.replace(/h|H/g,this.getHours());   
    str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());   
    str=str.replace(/m/g,this.getMinutes());
    str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());   
    str=str.replace(/s|S/g,this.getSeconds());
    return str;   
}  

//String类型转换成Date类型
function StringToDate(DateStr) 
{   
    var converted = Date.parse(DateStr); 
    var myDate = new Date(converted); 
    if (isNaN(myDate)) 
    {   
        var arys= DateStr.split('-'); 
        myDate = new Date(arys[0],--arys[1],arys[2]); 
    } 
    return myDate; 
}

//////////////////订单支付///////////////////////////
$(function(){
    $("#btnOrderPay").click(function(){
        if($("#hdfPayment").val()=="支付宝"){
            window.open("/pay/alipay/alipayto.aspx?orderNo="+$("#hdfOrderNo").val()+"&pay_bank="+$("#hdfPayBank").val());
        }
        if($("#hdfPayment").val()=="快钱"){
            window.open("/pay/99bill/send.aspx?orderNo="+$("#hdfOrderNo").val());
        }
        if($("#hdfPayment").val()=="Paypal"){
            window.open("/pay/paypal/reviewByPaypal.aspx?orderNo="+$("#hdfOrderNo").val());
        }
        if($("#hdfPayment").val()=="货到付款"){
            window.open("/cn/center/member/order/"+$('#hdfOrderNo').val()+"_info.html");
        }
        if($("#hdfPayment").val()=="预存款"){
            art.dialog.tips("正在提交数据，请稍候...",30);
            $.ajax({
                type:"POST",
                url:"/ashx/cn/1store/order_pay.ashx",
                data:"orderNo="+$("#hdfOrderNo").val(),
                success: function (msg) {
                    if(msg=="1001"){
                        art.dialog.tips("您的余额不足以支付订单金额！",1.5);
                    }if(msg=="1002"){
                        art.dialog.tips("你的订单已经支付，请不要重复支付！",1.5);
                    }
                    else if(msg=="1000"){
                        art.dialog.tips("恭喜您，支付成功！",3);
                        $.ajax({  
                            type:"POST",
                            url: "/ashx/cn/1store/async_send_message.ashx",  
                            data:"orderNo="+$("#hdfOrderNo").val()+"&sendType=2",
                            global: false,    
                            async:true,//jQuery API里面所有Demo都使用false,但是这里必须使用Default的true!  
                            success: function(){
                                location.href="/cn/center/member/order/"+$("#hdfOrderNo").val()+"_info.html";
                            }  
                        });
                    }
                }
            });   
        }  
        return false; 
    });
});







//////////////////////////////预存款充值//////////////////////////////////////
$(function(){
    $("#btnPay").click(function(){
        if($("#txtAlimoney").val()==""){
            $("#txtAlimoney").select();
            $("#spAlimoney").html("<img src=\"/cn/images/wrong.gif\" />请输入充值金额，充值金额最多保留两位小数！");
            return false;
        }else{
            if($("#txtAlimoney").val().match(/^\d*\.?\d{0,2}$/)==null){
                $("#txtAlimoney").select();
                $("#spAlimoney").html("<img src=\"/cn/images/wrong.gif\" />充值金额不符，充值金额最多保留两位小数！");
                return false;
            }else $("#spAlimoney").html("<img src=\"/cn/images/right.gif\"/>");
        }
        if($("input[name='pay_bank']:checked").val()==null){
            $("#spPay_bank").html("<img src=\"/cn/images/wrong.gif\" />请选择支付方式！");
            return false;
        }else $("#spPay_bank").html("<img src=\"/cn/images/right.gif\"/>");
        
        var oId="0";
        var payType="";
        if($("input[name='pay_bank']:checked").val()!="Paypal"&& $("input[name='pay_bank']:checked").val()!="99bill")
            payType="支付宝";
        else if($("input[name='pay_bank']:checked").val()=="99bill")
            payType="快钱";
        else
            payType="Paypal";
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/online_pay.ashx",
            data:"expenseMoney="+$("#txtAlimoney").val()+"&payType="+payType,
            global: true,    
            async:false,//jQuery API里面所有Demo都使用false,但是这里必须使用Default的true! 
            success:function(msg){
                if(msg!="0"){
                    oId=msg;
                }    
                else return false; 
            }
        });
        if($("input[name='pay_bank']:checked").val()!="Paypal"&& $("input[name='pay_bank']:checked").val()!="99bill"){
            window.open("/pay/alipay/alipayto.aspx?orderNo="+oId+"&alimoney="+$("#txtAlimoney").val()+"&pay_bank="+$("input[name='pay_bank']:checked").val());
        }else if($("input[name='pay_bank']:checked").val()=="99bill"){
            window.open("/pay/99bill/send.aspx?orderNo="+oId+"&alimoney="+$("#txtAlimoney").val());
        }else{
            window.open("/pay/Paypal/reviewByPaypal.aspx?orderNo="+oId+"&alimoney="+$("#txtAlimoney").val());
        }
        return false;
    });
});

//////////////////////////////商品订单//////////////////////////////////////
$(function(){
    $("#orderForm").submit(function(){
        window.location="/cn/center/member/order/" + escape($("#txtOrderNo").val()) + "_1.html";
        return false;
    });
});
function aConfirm(orderNo){
    art.dialog({
        id: 'testID',
        content: '您确定已收到货物了吗？',
        lock: true,
        fixed:true,
        opacity:0.1,
        button: [
            {
                name: '确定',
                callback: function () {
                    art.dialog.tips("正在确认，请稍候...",60);
                    $.ajax({
                        type:"POST",
                        url:"/ashx/cn/1store/confirm_receiving.ashx",
                        data:"orderNo="+orderNo, 
                        success: function (msg) {
                            if(msg=="1"){
                                window.location.reload();
                            }
                        }
                    });
                    return false;
                },
                focus: true
            },
            {
                name: '取消',
                callback: function () {
                    art.dialog.tips('你取消了操作');
                }
            }
        ]
    });
}



//////////////////////////////积分兑换订单//////////////////////////////////////
$(function(){
    $("#convertibilityOrderForm").submit(function(){
        window.location="/cn/center/member/convertibility/order/" + escape($("#txtOrderNo").val()) + "_1.html";
        return false;
    });
});
$(function(){
    $("#btnConvertibilityOrderPay").click(function(){
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/points_for_order_pay.ashx",
            data:"orderNo="+$("#hdfOrderNo").val(),
            success: function (msg) {
                if(msg=="1001"){
                    art.dialog.tips("您的消费积分不足以兑换订单积分！",1.5);
                }else if(msg=="1002"){
                    art.dialog.tips("你的订单已经兑换成功，请不要重复兑换！",1.5);
                    setTimeout("window.location.reload()",1500);
                }
                else if(msg=="1000"){
                    art.dialog.tips("恭喜您，兑换成功！",1.5);
                    setTimeout("window.location.reload()",1500);       
                }
            }
        });
        return false; 
    });
});


function aBulkMountJia(obj){
    poststr = "cid="+obj+"&amount="+(parseInt($("#amount"+obj).val())+1);
    send_request("/ashx/cn/1store/bulk_shopping_cart.ashx",poststr,function(){
        if (http_request.readyState==4 && http_request.status==200){
            changeBulkShoppingCart(http_request.responseText);
        }    
    });
}
function aBulkMountJian(obj){
    if(parseInt($("#amount"+obj).val())>1){
        poststr = "cid="+obj+"&amount="+(parseInt($("#amount"+obj).val())-1);
        send_request("/ashx/cn/1store/bulk_shopping_cart.ashx",poststr,function(){
            if (http_request.readyState==4 && http_request.status==200){
                changeBulkShoppingCart(http_request.responseText);
            }    
        });
    }
}
function changeBulkMount(obj){
    if(parseInt($("#amount"+obj).val())==0){
        art.dialog.tips("购买数量不能为0！",1.5);
        return false;
    }  
    else{
        poststr = "cid="+obj+"&amount="+$("#amount"+obj).val();
        send_request("/ashx/cn/1store/bulk_shopping_cart.ashx",poststr,function(){
            if (http_request.readyState==4 && http_request.status==200){
                changeBulkShoppingCart(http_request.responseText);
            }    
        });
    }    
}
function changeBulkShoppingCart(obj){
    if(obj=="1001")
        TB_show(null, "/cn/login.html?TB_iframe=true&height=370&width=640", false);
    else if(obj=="1003")
        art.dialog.tips("很抱歉，商品数量修改失败！",1.5);
    else{
        var returnValue=obj.split("〇");
        if(returnValue[0]=="1002")
           art.dialog.tips("很抱歉，商品数量修改失败,商品库存不足！",1.5);
        $("#tbBulkShoppingCart").html(returnValue[1]);
        $("#pBulkTotal").html(returnValue[2]);
    }
}


//////////////////////////////在线留言表单//////////////////////////////////////
$(function(){
    $("#btnOnlineMessageSubmit").click(function(){
        if($("#txtTitle").val()==""){
            $("#txtTitle").focus();
            $("#spTitle").html("<img src=\"/cn/images/wrong.gif\" />请输入标题！");
            return false;
        }else{
            $("#spTitle").html("<img src=\"/cn/images/right.gif\" />");
        }
        if($("#txtaContent").val()==""){
            $("#txtaContent").select();
            $("#spContent").html("<img src=\"/cn/images/wrong.gif\" />请输入内容！");
            return false;
        }else{
            if($("#txtaContent").val().length>500){
                $("#txtaContent").select();
                $("#spContent").html("<img src=\"/cn/images/wrong.gif\" />内容不能超过500个字符！");
                return false;
            }else $("#spContent").html("<img src=\"/cn/images/right.gif\" />");
        }
        if($("#txtOnlineMessageCode").val()==""){
            $("#txtOnlineMessageCode").select();
            $("#spOnlineMessageCode").html("<img src=\"/cn/images/wrong.gif\" />请输入验证码！");
            return false;
        }else $("#spOnlineMessageCode").html("<img src=\"/cn/images/right.gif\" />");
        $.ajax({
            type:"POST",
            url:"/ashx/cn/1store/online_message.ashx",
            data:"title="+escape($("#txtTitle").val())+"&contact="+escape($("#txtContact").val())+"&content="+escape($("#txtaContent").val())+"&code="+$("#txtOnlineMessageCode").val(),
            success:function(msg){
                if(msg=="1001"){
                    $("#txtOnlineMessageCode").select();
                    $("#spOnlineMessageCode").html("<img src=\"/cn/images/wrong.gif\" />验证码错误，请重新输入！");
                    $("#imgOnlineMessageCheckCode").attr("src","/code/"+ parseInt(10000*Math.random())+"_onlineMessage.html");
                }else if(msg=="1000"){
                    art.dialog.tips("恭喜您，发布成功！",1.5);
                    setTimeout("location.href='/cn/online/message/1.html'",2000);
                }else art.dialog.tips("很抱歉，发布失败！",1.5);
            }
        });
        return false;
    });
});



